package servidorLocalizacion.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import servidorLocalizacion.servidor.Celda;

public class CeldaDAO {

	public static CeldaDAO instance;
	public Connection connection;
	
	public static void init() throws ClassNotFoundException, SQLException{
		instance = new CeldaDAO();
		instance.connection = DAOServidorLocalizacion.getConnection();
	}
	
	public static void close(){
		instance = null;
	}
	
	public static Celda getCelda(int id) throws SQLException{
		return instance.getCoordenadas(id);
	}
	
	public Celda getCoordenadas(int id) throws SQLException{
		PreparedStatement smt = connection.prepareStatement("SELECT * FROM CELDA WHERE ID = ?");
		smt.setInt(1, id);
		ResultSet rs = smt.executeQuery();
		rs.next();
		return new Celda(rs.getString(2), rs.getString(3));
	}

}
